package behavioral_pattern.interpreter_pattern;

import java.util.Stack;

/**
 * @version: 1.0
 * @Description: TODO
 * @author: zZmH
 * @date: 2020/12/07 16:46
 */


public class InstructionHandler {
    private String instruction;
     AbsNode absNode;

    public InstructionHandler(String instruction) {
        this.instruction = instruction;

    }

    public static void main(String[] args) {

        Stack<AbsNode> stack = new Stack<>();
        InstructionHandler instructionHandler = new InstructionHandler("up walk 5 and down run 10 and left move 3");

    }

}
abstract class AbsNode{
    abstract String interpret();
}

class AndNode extends AbsNode{
    AbsNode left;
    AbsNode right;

    @Override
    String interpret() {
        return left.interpret() + " 然后" + right.interpret();
    }
}
class SentenceNode extends AbsNode{
    DirectNode directNode;
    ActionNode actionNode;
    DistanceNode distanceNode;

    public SentenceNode(DirectNode directNode, ActionNode actionNode, DistanceNode distanceNode) {
        this.directNode = directNode;
        this.actionNode = actionNode;
        this.distanceNode = distanceNode;
    }

    @Override
    String interpret() {
        return directNode.interpret() + " " + actionNode.interpret() + " " + distanceNode.interpret();
    }
}

//方向
class DirectNode extends AbsNode {
    String direct;

    public DirectNode(String direct) {
        this.direct = direct;
    }

    @Override
    String interpret() {
        switch (direct) {
            case "up":
                return "向上";
            case "down":
                return "向下";
            case "left":
                return "向左";
            case "right":
                return "向右";
            default:
                return "";
        }

    }
}
//行动
class ActionNode extends AbsNode{
    String action;

    public ActionNode(String action) {
        this.action = action;
    }

    @Override
    String interpret() {
        switch (action) {
            case "run":
                return "跑";
            case "walk":
                return "走";

            default:
                return "爪巴";
        }
    }
}
//距离
class DistanceNode extends AbsNode{
    String dist;
    @Override
    String interpret() {
        return dist;
    }

}